package DControl;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class DRadio extends DComponent implements DMouseListener{
	boolean isSelect = false;
	DRadioGroup group;
	
	public DRadio()
	{
		init();
		setResponseRect(x, y, x + 13, y + 13);
	}
	
	public DRadio(String text)
	{
		init();
		this.text = text;
		setResponseRect(x, y, x + 13, y + 13);
	}
	
	public DRadio(int x,int y,String text)
	{
		init();
		this.x = x;
		this.y = y;
		this.text = text;
		setResponseRect(x, y, x + 13, y + 13);
	}
	
	public void init()
	{
		x = 0;
		y = 0;
		text = "Radio";
		color = Color.LIGHT_GRAY;
		Class = "DRadio";
		this.color = color.pink;
	}
	
	 public void paintComponent(Graphics g)
	 {
		 g.setColor(Color.gray);
		 g.drawOval(x-1, y-1, 14, 14);
		 g.setColor(Color.white);
		 g.fillOval(x, y, 13, 13);
		 if(isSelect)
		 {
			 g.setColor(color);
			 g.fillOval(x+2, y+2, 8, 8); 
		 }
		 g.setColor(Color.black);
		 g.drawString(text, x+18, y+11);
		 g.setColor(color);
	 }
	 
	 public boolean isSelect()
	 {
		 if(isSelect)
			 return true;
		 else
			 return false;
	 }
	 
	 public void setSelect(boolean flag)
	 {
		 this.isSelect = flag;
	 }
	 
	 public void getGroup(DRadioGroup group)
	 {
		 this.group = group;
	 }

	 
	  public void mouseEntered(MouseEvent e){}
	   	 
	  public void mouseExited(MouseEvent e){}
	   	 
	  public void mousePressed(MouseEvent e) 
	  {
		  group.setRadio(this);
		  isSelect = true;
		  group.mousePressed(e);
	   		 repaint();

		  if(listener != null)
		  {
			  listener.mousePressed(e);
		  }
	   		 
	  }
	   	 
	  public void mouseReleased(MouseEvent e){}
	   	 
	  public void mouseClicked(MouseEvent e){}
	
}